package com.yangle.frame.admin.config;

import com.yangle.frame.admin.convert.StringToDateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import javax.annotation.PostConstruct;

/**
 * Created by yangle on 2018/8/12.
 */
@Configuration
public class WebConfigBeans {
    @Autowired
    private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
    @PostConstruct
    public void initEditableValidation()
    {
        ConfigurableWebBindingInitializer configurableWebBindingInitializer= (ConfigurableWebBindingInitializer) requestMappingHandlerAdapter.getWebBindingInitializer();
        if(configurableWebBindingInitializer.getConversionService()!=null){
            GenericConversionService genericConversionService= (GenericConversionService) configurableWebBindingInitializer.getConversionService();
            genericConversionService.addConverter(new StringToDateConverter());
        }
    }}
